import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Index from '@/components/index'
import Hello from '@/components/Hello'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: resolve => require(['../components/Login'], resolve),
      beforeEnter: (to, from, next) =>{
        if(localStorage.getItem('login')){
          next('/index')
        }
        next();
      }
    },
    {
    	path: '/index',
    	component: resolve => require(['../components/index'], resolve),
      beforeEnter: (to, from, next) =>{
        if(!localStorage.getItem('login')){
          next('/')
        }
        next();
      },
    	children:[
    		{
    			path: 'Hello',
    			component: resolve => require(['../components/Hello'], resolve)
    		}
    	]
    }
  ]
})
